package com.sort;


import java.util.Arrays;

/**
 * Created by yijy on 2018/3/8.
 */
public class QuickSort {

    public static void main(String[] args) {
        int[] arr ={2,10,1,6,12,8,0,3,20};
        new QuickSort().QuickSort(arr,0,arr.length-1);
        System.out.println(Arrays.toString(arr));
    }

    public void QuickSort(int[] arr,int low,int high){
        if(low<high){
            int middle = getMiddle(arr,low,high);
            QuickSort(arr,low,middle-1);
            QuickSort(arr,middle+1,high);
        }
    }

    public int getMiddle(int[] arr,int low,int high){
        int temp = arr[low];
        while (low<high){
            while (low<high && arr[high]>temp){
                high--;
            }
            arr[low] = arr[high];
            while (low<high && arr[low]<temp){
                low++;
            }
            arr[high] = arr[low];
        }
        arr[low] = temp;
        return low;
    }


}
